home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group96a.txt
/
000085_icon-group-sender _Mon Apr 15 09:14:19 1996.msg
< prev
next >
Wrap
Internet Message Format
|
1996-09-05
|
2KB
Received: by cheltenham.cs.arizona.edu; Mon, 15 Apr 1996 12:27:19 MST
Date: Mon, 15 Apr 1996 09:14:19 -0700
From: kwalker@orville.premenos.com (Ken Walker)
Message-Id: <199604151614.JAA23070@varda.premenos.com>
To: icon-group@cs.arizona.edu
Subject: Re: random numbers...
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Md5: LpZpYRJRiHqugYwp9aw+jg==
Errors-To: icon-group-errors@cs.arizona.edu
Status: O
> Date: 15 Apr 96 09:27:09 BST
> From: R J Hare <rjhare@tattoo.ed.ac.uk>
>
> I'm writing a graphics program which requires that I perturb my x and
> y values randomly by -1|0|1 before plotting the object at the new x and y.
> There seem to be 2 obvious ways of doing this:
>
> x := x-2+?3
> y := y-2+?3
>
> or:
>
> x := x+?[-1,0,1]
> y := y+?[-1,0,1]
>
> Which is 'best' (quicker, easier to read, etc.)?
I find the second easiest to read, but it has the disadvantage of constructing
lists every time it is executed. If you are interested in effeciency, you
might want to precompute the perturbations:
procedure foo()
static perturbations
initial perturbations := [-1, 0, 1]
...
x := x + ?perturbations
y := y + ?perturbations
...
end
Even with this modification, it is likely to run a little slower than
the first method, but the difference may not be significant for your
application.
Ken Walker, kwalker@premenos.com
Premenos Coporation, Concord, Ca. 94520